<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class DiscountsApiController extends AbstractRestfulController
{
    public function getList()
    {	
		header('Access-Control-Allow-Origin: *');
		$discountTable=$this->getServiceLocator()->get('Models\Model\DiscountsFactory');			
		$AllDiscounts = $discountTable->getAllDiscounts()->toArray();
		if(count($AllDiscounts)!=0){
			return new JsonModel(array(
				'output'	=> 'success',
				'result'		=>	json_encode($AllDiscounts),
				'value'		=> 1,
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
				'value'		=> 0,
			));
		}
    }
    public function get($user_id)
    {
		header('Access-Control-Allow-Origin: *');
		$discountTable=$this->getServiceLocator()->get('Models\Model\DiscountsFactory');
		$explodeId=explode('-',$user_id);
		$user_id=$explodeId[0];
		$userDiscounts = $discountTable->userDiscounts($user_id);
		if($userDiscounts->count()){
			return new JsonModel(array(
				'output'	=> 'success',
				'result'		=>	json_encode($userDiscounts->toArray()),
				'value'		=> 1,
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
				'value'		=> 0,
			));
		}
    }
    public function create($reviewAndRating)
    {
		
    }
    public function update($tracking_id,$data)
    {
		header('Access-Control-Allow-Origin: *');
		$discountTable=$this->getServiceLocator()->get('Models\Model\DiscountsFactory');
		$orderDeliveryTable=$this->getServiceLocator()->get('Models\Model\OrderDeliveryDetailsFactory');
		$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
		$paidstatus= $discountTable->paidDiscount($tracking_id);
		$getShopId=$orderDeliveryTable->getComplaintshopId($tracking_id)->toArray();
		if($getShopId){
			$sendConfirmDiscount=$notificationTable->sendcancelledComplaint($data,'1',$data['admin_id'],$getShopId[0]['shop_id'],'0','3','0');
		}
		if($paidstatus){
			return new JsonModel(array(
				'output'	=> 'success',
				'value'		=> 1,
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
				'value'		=> 0,
			));
		}
    }
    public function delete($id)
    {
       
    }
}